package com.example.pei.papa.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;
import com.example.pei.papa.R;

public class register_step_three_Activity extends AppCompatActivity implements View.OnClickListener{
    private Button button_back_to_step_two;
    private Button button_delete;
    private Button button_to_step_four;
    private EditText EditText_username;
    private EditText EditText_password;

    private String username;
    private String password;
    private String phone;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_step_three_);
        ViewInit();
        Intent intent=getIntent();
        phone=intent.getStringExtra("phoneString");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_back_to_step_two: finish();break;
            case R.id.btn_delete:   EditText_password.setText("");break;
            case R.id.btn_to_step_four: btn_to_step_four_Click();break;
        }
    }

    private void ViewInit(){
        button_back_to_step_two=(Button)findViewById(R.id.btn_back_to_step_two);
        button_delete=(Button)findViewById(R.id.btn_delete);
        button_to_step_four=(Button)findViewById(R.id.btn_to_step_four);
        EditText_username=(EditText)findViewById(R.id.ed_username);
        EditText_password=(EditText)findViewById(R.id.et_password);

        //设置监听
        button_back_to_step_two.setOnClickListener(this);
        button_delete.setOnClickListener(this);
        button_to_step_four.setOnClickListener(this);
    }
    private void btn_to_step_four_Click(){
        username=EditText_username.getText().toString();
        password=EditText_password.getText().toString();

        Intent intent=new Intent("register_step_4_Activity");
        intent.putExtra("phoneString",phone);
        intent.putExtra("userNameString",username);
        intent.putExtra("passWordString",password);
        startActivity(intent);

//        UserInfo userInfo=new UserInfo();
//        userInfo.setMobilePhoneNumber(phone);
//        userInfo.setUsername(username);
//        userInfo.setPassword(password);
//        userInfo.signUp(new SaveListener<UserInfo>() {
//            @Override
//            public void done(UserInfo s, BmobException e) {
//                if(e==null){
//                    Toast.makeText(register_step_three_Activity.this,"注册成功，返回objectId为："+s,Toast.LENGTH_SHORT).show();
//                }else{
//                    Toast.makeText(register_step_three_Activity.this,"注册失败 Code：" + e.getMessage(),Toast.LENGTH_LONG).show();
//                }
//            }
//        });

    }
}
